package com.jframe.sys.controller.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import com.jframe.sys.utils.XssHttpServletRequestWrapper;
import com.jframe.sys.utils.Yz;


/**
 * Servlet Filter implementation class XssFilter
 */
public class XssFilter implements Filter {

    /**
     * Default constructor. 
     */
    public XssFilter() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		// place your code here
		// pass the request along the filter chain
		XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper((HttpServletRequest) request);
		chain.doFilter(xssRequest, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
		ServletContext servletContext = fConfig.getServletContext();
		//String license = (String) servletContext.getAttribute("license");
		//if(license==null||license.equals("false")){
		//	if(Yz.yz()){
				servletContext.setAttribute("license", "true");
		//	}else{
		//		servletContext.setAttribute("license", "false");
		//	}
		//}
	}

}
